package com.hs.srm.admin.modules.notice.controller;

import com.hs.srm.admin.modules.notice.entity.NoticeMainInfoEntity;
import com.hs.srm.admin.modules.notice.service.NoticeMainInfoService;
import com.hs.srm.admin.modules.sys.controller.AbstractController;
import com.hs.srm.common.utils.MapUtils;
import com.hs.srm.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * @author wangpeidong
 * @email wangpdcn@163.com
 * @date 2018-06-28 21:37:31
 */
@RestController
@RequestMapping("/noticeMainInfo")
public class NoticeMainInfoController extends AbstractController {

    @Autowired
    private NoticeMainInfoService noticeMainInfoService;

    /**
     * 获取当前用户的通知信息
     *
     * @return
     */
    @GetMapping("/noticeList")
    public R noticeList() {
        Long userId = this.getUser().getUserId();
        List<NoticeMainInfoEntity> noticeList = noticeMainInfoService.selectByMap(new MapUtils().put("user_id", userId));
        noticeList.sort((a, b) -> a.getCreateTime().after(b.getCreateTime()) ? -1 : 1);
        return R.ok(noticeList);
    }

    /**
     * 通过id 删除消息
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteNotice")
    public R deleteNotice(@RequestParam(value = "ids[]") Integer[] ids) {
        noticeMainInfoService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}
